package com.ss.android.article.base.feature.detail.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.RelativeLayout;
import android.widget.Scroller;

import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.UIUtils;
import com.ss.android.article.base.ui.MyWebViewV9;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.util.LoadUrlUtils;

public class DetailScrollView extends ViewGroup {
    public MyWebViewV9 mMyWebViewV9;
    public View mDetailInfoFirstHeader2;
    public boolean c = true;
    public int mLayoutType = 1;
    public boolean g = false;
    public boolean mEnableDetectContentSizeChange;
    MyOnChangedListener mMyOnChangedListener;
    int f;
    int h = 300;
    boolean isFingerDown = false;
    Runnable k = new Runnable() {

        public final void run() {
            if (DetailScrollView.this.f != DetailScrollView.this.getScrollY()) {
                DetailScrollView.this.f = DetailScrollView.this.getScrollY();
                DetailScrollView.this.postDelayed(DetailScrollView.this.k, DetailScrollView.this.h);
            } else if (DetailScrollView.this.mMyOnChangedListener != null) {
                DetailScrollView.this.g = false;
                DetailScrollView.this.mMyOnChangedListener.a();
            }
        }
    };
    private int mScaledMaxFlingVelocity;
    private boolean mShowBottomViewOnFirstLayout = false;
    private boolean mDisableInfoLayer = false;
    private boolean mDisableScrollOver = false;
    private boolean mIsVerticalScrollBarEnabled;
    private int F;
    private float G = 1f;
    private Scroller mScroller;
    private MyListViewV9 mMyListViewV9;
    private RelativeLayout mBottomListViewLayout;
    private View mNightModeOverlay;
    private float p;
    private int dp3;
    private boolean mDisallowIntercept = false;
    private int mY;
    private int t;
    private int u;
    private VelocityTracker mVelocityTracker;
    private int mPointerId = -1;
    private boolean isMoving = false;
    private boolean pendingDrag = false;
    private int mScaledTouchSlop;

    public DetailScrollView(Context context) {
        super(context);
        this.init(context);
    }

    public DetailScrollView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.init(context);
    }

    public DetailScrollView(Context context, AttributeSet attributeSet, int defaultStyle) {
        super(context, attributeSet, defaultStyle);
        this.init(context);
    }

    static boolean awakenScrollBars(DetailScrollView detailScrollView) {
        return detailScrollView.awakenScrollBars();
    }

    private void init(Context context) {
        this.setMotionEventSplittingEnabled(false);
        ViewConfiguration configuration = ViewConfiguration.get(context);
        this.mScaledTouchSlop = configuration.getScaledTouchSlop();
        this.mScaledMaxFlingVelocity = configuration.getScaledMaximumFlingVelocity();
        UIUtils.dp2px(context, 80f);
        this.dp3 = ((int) UIUtils.dp2px(context, 3f));
        this.p = 300f / UIUtils.dp2px(context, 420f);
    }

    private void getYAndPointerId(MotionEvent motionEvent) {
        int index = motionEvent.getActionIndex();
        if (motionEvent.getPointerId(index) == this.mPointerId) {
            index = index == 0 ? 1 : 0;
            this.mY = ((int) motionEvent.getY(index));
            this.mPointerId = motionEvent.getPointerId(index);
            if (this.mVelocityTracker != null) {
                this.mVelocityTracker.clear();
            }
        }
    }

    private void onEvent(String event) {
        MobClickCombiner.onEvent(this.getContext(), "detail", event);
    }

    private void handOpenDrawer(boolean arg8, boolean arg9, int dy) {
        int v4 = 350;
        int v0 = 200;
        boolean v3 = false;
        if (this.mLayoutType != 2) {
            Logger.d("DetailScrollView", "handOpenDrawer()");
            this.mScroller.abortAnimation();
            this.webViewScrollTo(arg9);
            if (!arg9 && this.mMyListViewV9 != null && this.mMyListViewV9.getVisibility() == VISIBLE) {
                this.mMyListViewV9.setSelection(0);
            }

            if (arg8) {
                int startX = this.getScrollX();
                int startY = this.getScrollY();
                int duration = ((int) ((((float) Math.abs(dy))) * this.p));
                if (duration >= v0) {
                    v0 = duration > v4 ? v4 : duration;
                }

                duration = this.mDisableScrollOver ? 0 : v0;
                this.mScroller.startScroll(startX, startY, 0, dy, duration);
                ViewCompat.postInvalidateOnAnimation(this);
                this.f();
            } else {
                this.scrollBy(0, dy);
            }

            if (!arg9) {
                v3 = true;
            }

            this.c = v3;
            if (this.mMyOnChangedListener == null) {
                return;
            }

            this.mMyOnChangedListener.setInfoTitleBarVisibility(arg9);
        }
    }

    public final void handOpenDrawer() {
        if (this.getVisibility() == VISIBLE) {
            int scrollY = this.getScrollY();
            if (scrollY > 20) {
                this.handOpenDrawer(true, false, -scrollY);
            }
        }
    }

    protected final void startFling(int expectedVelocityY) {
        if (this.getChildCount() > 0 && !this.mDisableScrollOver && !this.mDisableInfoLayer) {
            int startX = this.getScrollX();
            int startY = this.getScrollY();
            int velocityY = expectedVelocityY > 0 ? Math.min(expectedVelocityY, this.mScaledMaxFlingVelocity)
                    : Math.max(expectedVelocityY, -this.mScaledMaxFlingVelocity);
            int maxY = this.mMyListViewV9.supportFling() ? Integer.MAX_VALUE : Math.max(0, this.getWebViewHeight());
            int minY = this.mMyWebViewV9.getVisibility() == VISIBLE ? -((int) ((float) this.mMyWebViewV9.getContentHeight() * this.mMyWebViewV9.getScale())) : 0;
            this.mScroller.fling(startX, startY, 0, velocityY, 0, 0, minY, maxY);
            ViewCompat.postInvalidateOnAnimation(this);
            this.f();
            Logger.d("DetailScrollView", "start fling, velocityY = " + velocityY);
        }
    }

    final void onOverScrolled(View view, int scrollY, boolean clampedY, int lastDeltaY, int scrollRangeY) {
        if (this.isFingerDown
                && !this.mDisableScrollOver
                && !this.mDisableInfoLayer
                && this.mScroller.isFinished()) {
            if (view == this.mMyWebViewV9) {
                if (this.getScrollY() == 0
                        && view.getScrollY() >= 0
                        && clampedY
                        && lastDeltaY > 0) {
                    this.startDragAsClampedY(false);
                    this.c = true;
                }

                this.t = scrollRangeY;
            } else {
                if (view == this.mMyListViewV9) {
                    if (this.getScrollY() != this.getWebViewHeight()) {
                        return;
                    }
                    if (scrollY < 0) {
                        this.c = false;
                        this.startDragAsClampedY(true);
                        return;
                    }
                    if (view.getScrollY() != 0) {
                        return;
                    }
                    if (!clampedY) {
                        return;
                    }
                    if (lastDeltaY >= 0) {
                        return;
                    }
                    this.startDragAsClampedY(true);
                    this.c = false;
                }
            }
        }
    }

    public final boolean handleOpenDrawer(boolean arg4) {
        int scrollY = this.getScrollY();
        boolean v2 = scrollY < this.getWebViewHeight() / 2;
        scrollY = v2 ? this.getWebViewHeight() - scrollY : -scrollY;
        this.onEvent(v2 ? "handle_open_drawer" : "handle_close_drawer");
        this.handOpenDrawer(arg4, v2, scrollY);
        return v2;
    }

    public final void webViewScrollTo(boolean arg4) {
        if (this.mMyWebViewV9 != null && this.mMyWebViewV9.getVisibility() == VISIBLE) {
            int v1 = this.t > 0 ? 1 : 0;
            int y;
            if (arg4) {
                y = v1 != 0 ? this.t : (int) ((float) this.mMyWebViewV9.getContentHeight() * this.mMyWebViewV9.getScale());
                this.u = this.mMyWebViewV9.getScrollY();
            } else {
                y = this.u;
            }
            Logger.d("DetailScrollView", "webViewScrollTo()   y=" + y);
            if (v1 != 0 || !this.mMyWebViewV9.getSettings().getJavaScriptEnabled()) {
                this.mMyWebViewV9.scrollTo(this.mMyWebViewV9.getScrollX(), y);
            } else {
                LoadUrlUtils.loadUrl(this.mMyWebViewV9, "javascript:window.scrollTo(" + this.mMyWebViewV9.getScrollX() + "," + y + ");");
            }
            this.mMyWebViewV9.mDeltaYRecorderList.clear();
        }
    }

    private int getWebViewHeight(int input) {
        if (this.mMyWebViewV9 != null) {
            int webViewHeight = this.mMyWebViewV9.getLayoutParams().height;
            if (webViewHeight > 0) {
                input = webViewHeight;
            }
        }
        return input;
    }

    public final void checkOpenDrawer() {
        if (this.getVisibility() == VISIBLE) {
            int scrollY = this.getScrollY();
            if (scrollY < this.getWebViewHeight() / 2) {
                this.onEvent("handle_open_drawer");
                this.handOpenDrawer(true, true, this.getWebViewHeight() - scrollY);
            }
        }
    }

    private void cleanVelocityTracker() {
        if (this.mVelocityTracker == null) {
            this.mVelocityTracker = VelocityTracker.obtain();
        } else {
            this.mVelocityTracker.clear();
        }
    }

    private void startDragAsClampedY(boolean arg4) {
        if (!this.isMoving && this.isFingerDown && this.mPointerId != -1) {
            if (arg4) {
                this.scrollTo(0, this.getWebViewHeight() - this.dp3);
            } else {
                this.scrollTo(0, this.dp3);
            }
            this.pendingDrag = true;
        }
    }

    protected boolean checkLayoutParams(ViewGroup.LayoutParams layoutParams) {
        return layoutParams instanceof ViewGroup.MarginLayoutParams;
    }

    @Override
    public void computeScroll() {
        if (this.mScroller.isFinished() || !this.mScroller.computeScrollOffset()) {
            if (!this.mEnableDetectContentSizeChange) {
                return;
            }

            if (this.mMyWebViewV9 == null) {
                return;
            }

            int scrollY = this.getScrollY();
            mMyWebViewV9.setDetectContentSize(this.mLayoutType == 1
                    && this.mMyWebViewV9.getVisibility() == VISIBLE
                    && scrollY > 0
                    && scrollY < this.getWebViewHeight());
        } else {
            int webViewHeight = this.getWebViewHeight();
            int oldX = this.getScrollX();
            int oldY = this.getScrollY();
            int x = this.mScroller.getCurrX();
            int y = this.mScroller.getCurrY();
            Logger.d("DetailScrollView", "computeScroll, mScroller.getFinalY() = " + this.mScroller.getFinalY()
                    + ", mScroller.getStartY() = " + this.mScroller.getStartY());

            Logger.d("DetailScrollView", "computeScroll, oldX = " + oldX
                    + ", oldY = " + oldY
                    + ", x = " + x
                    + ", y = " + y
                    + "webViewHeight=" + webViewHeight);
            if (y <= oldY || oldY < webViewHeight) {
                if (y < oldY && oldY <= 0 && this.mMyWebViewV9.getVisibility() == VISIBLE) {
                    int vy = this.getCappedCurVelocity();
                    if (vy != 0) {
                        this.mScroller.forceFinished(true);
                        this.mMyWebViewV9.flingScroll(0, -vy);
                        if (Logger.debug()) {
                            Logger.d("DetailScrollView", "computeScroll, abort fling, WebView start fling, velocity = " + -vy + ", scrollY = " + oldY);
                        }
                        return;
                    }
                }
            } else if (this.mMyListViewV9.getVisibility() == VISIBLE) {
                int cv = this.getCappedCurVelocity();
                if (cv != 0 && this.mMyListViewV9.tryFling(cv)) {
                    this.mScroller.forceFinished(true);
                    if (Logger.debug()) {
                        Logger.d("DetailScrollView", "computeScroll, abort fling, ListView start fling, velocity = " + cv + ", scrollY = " + oldY);
                    }
                    return;
                }
            }

            int scrollY = Math.max(0, Math.min(y, webViewHeight));
            if (oldX != x || oldY != scrollY) {
                this.scrollTo(x, scrollY);
                if (scrollY == webViewHeight) {
                    this.c = false;
                }
            }
            ViewCompat.postInvalidateOnAnimation(this);
            if (!this.mEnableDetectContentSizeChange) {
                return;
            }
            if (this.mMyWebViewV9 == null) {
                return;
            }
            this.mMyWebViewV9.setDetectContentSize(false);
        }
    }

    protected int computeVerticalScrollExtent() {
        return !this.mIsVerticalScrollBarEnabled || this.mMyWebViewV9 == null
                ? super.computeVerticalScrollExtent()
                : (int) ((float) this.mMyWebViewV9.computeVerticalScrollExtent() + (float) this.mMyListViewV9.computeVerticalScrollExtent() * this.G);
    }

    protected int computeVerticalScrollOffset() {
        if (!this.mIsVerticalScrollBarEnabled || this.mMyWebViewV9 == null) {
            return super.computeVerticalScrollOffset();
        } else {
            int verticalScrollOffset = this.mMyWebViewV9.computeVerticalScrollOffset();
            if (this.getScrollY() > 0) {
                verticalScrollOffset = (int) ((float) verticalScrollOffset + (float) this.mMyListViewV9.computeVerticalScrollOffset() * this.G);
            }
            return verticalScrollOffset;
        }
    }

    @Override
    protected int computeVerticalScrollRange() {
        int v0 = !this.mIsVerticalScrollBarEnabled || this.mMyWebViewV9 == null
                ? super.computeVerticalScrollRange()
                : ((int) ((float) this.mMyWebViewV9.getComputedVerticalScrollRange() + (float) this.mMyListViewV9.computeVerticalScrollRange() * this.G));
        return v0;
    }

    private void ensureVelocityTracker() {
        if (this.mVelocityTracker == null) {
            this.mVelocityTracker = VelocityTracker.obtain();
        }
    }

    public boolean dispatchTouchEvent(MotionEvent motionEvent) {
        boolean handled;
        if (motionEvent.getActionMasked() == MotionEvent.ACTION_DOWN) {
            this.F = 0;
        }

        try {
            handled = super.dispatchTouchEvent(motionEvent);
        } catch (Exception exception) {
            exception.printStackTrace();
            handled = false;
        }

        switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_DOWN:
                this.isFingerDown = true;
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                this.isFingerDown = false;
                break;
        }
        return handled;
    }

    private void destroyVelocityTracker() {
        if (this.mVelocityTracker != null) {
            this.mVelocityTracker.recycle();
            this.mVelocityTracker = null;
        }
    }

    private void f() {
        this.g = true;
        this.f = this.getScrollY();
        this.postDelayed(this.k, this.h);
    }

    private void g() {
        this.isMoving = false;
        this.destroyVelocityTracker();
    }

    protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
        return new ViewGroup.MarginLayoutParams(-1, -1);
    }

    public ViewGroup.LayoutParams generateLayoutParams(AttributeSet arg3) {
        return new ViewGroup.MarginLayoutParams(this.getContext(), arg3);
    }

    protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams arg4) {
        return new ViewGroup.MarginLayoutParams(arg4.width, arg4.height);
    }

    private int getCappedCurVelocity() {
        return Math.min(((int) this.mScroller.getCurrVelocity()), this.mScaledMaxFlingVelocity);
    }

    private int getScrollRange() {
        return this.getWebViewHeight() * 2;
    }

    public int getWebViewHeight() {
        return this.getWebViewHeight(this.getHeight());
    }

    protected void onFinishInflate() {
        super.onFinishInflate();
        this.mScroller = new Scroller(this.getContext());
        this.mMyWebViewV9 = this.findViewById(com.ss.android.article.browser.R.id.top_webview);
        this.mMyListViewV9 = this.findViewById(com.ss.android.article.browser.R.id.bottom_listview);
        this.mBottomListViewLayout = this.findViewById(com.ss.android.article.browser.R.id.bottom_listview_layout);
        this.mNightModeOverlay = this.findViewById(com.ss.android.article.browser.R.id.night_mode_overlay);
        this.mMyWebViewV9.setOnOverScrolledListener(new OnOverScrolledListener() {

            public final void fling(int velocityY) {
                if (!DetailScrollView.this.isFingerDown) {
                    DetailScrollView.this.startFling((int) ((float) velocityY * 0.6f));
                }
            }

            public final void onOverScrolled(View view, int scrollY,
                                             boolean clampedY,
                                             int lastDeltaY,
                                             int scrollRangeY) {
                DetailScrollView.this.onOverScrolled(view, scrollY, clampedY, lastDeltaY, scrollRangeY);
            }
        });
        mMyWebViewV9.setOverScrollMode(0);
        mMyWebViewV9.computeVerticalScrollRange();
        this.mMyWebViewV9.setContentSizeChangeListener(new MyWebViewV9.DetailScrollViewHolder(this));
        this.mMyListViewV9.setOnOverScrolledListener(new OnOverScrolledListener() {

            public final void fling(int velocityY) {
                if (!DetailScrollView.this.isFingerDown) {
                    DetailScrollView.this.startFling(velocityY);
                }
            }

            public final void onOverScrolled(View view, int scrollY, boolean clampedY, int lastDeltaY, int scrollRangeY) {
                DetailScrollView.this.onOverScrolled(view, scrollY, clampedY, lastDeltaY, scrollRangeY);
            }
        });
        this.mMyListViewV9.setOverScrollMode(0);
        this.setLayoutType(this.mLayoutType);
    }

    public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
        if (this.mDisableScrollOver || this.mDisableInfoLayer || this.mDisallowIntercept) {
            return false;
        } else {
            if (motionEvent.getActionMasked() == MotionEvent.ACTION_MOVE && this.isMoving) {
                return true;
            }
            switch (motionEvent.getActionMasked()) {
                case MotionEvent.ACTION_DOWN:
                    this.pendingDrag = false;
                    this.mY = ((int) motionEvent.getY());
                    this.mPointerId = motionEvent.getPointerId(0);
                    this.cleanVelocityTracker();
                    this.mVelocityTracker.addMovement(motionEvent);
                    this.isMoving = !this.mScroller.isFinished();
                    break;
                case MotionEvent.ACTION_MOVE: {
                    if (mPointerId == -1) {
                        return this.isMoving;
                    }

                    int pointerIndex = motionEvent.findPointerIndex(mPointerId);
                    if (pointerIndex == -1) {
                        Logger.w("DetailScrollView", "Invalid pointerId=" + mPointerId + " in onInterceptTouchEvent");
                        return this.isMoving;
                    }

                    int y = (int) motionEvent.getY(pointerIndex);
                    int deltaY = Math.abs(y - this.mY);
                    if (!this.isMoving && this.mScroller.isFinished()) {
                        int scrollY = this.getScrollY();
                        if (scrollY == 0 && y <= this.mMyWebViewV9.getBottom() - scrollY) {// webView过短？
                            this.mY = y;
                            return this.isMoving;
                        }

                        if (scrollY == this.getWebViewHeight()) {// webview 滑动完了
                            if (deltaY > this.mScaledTouchSlop
                                    && y > this.mY
                                    && this.mMyListViewV9.getScrollY() == 0
                                    && this.mDetailInfoFirstHeader2 != null
                                    && this.mDetailInfoFirstHeader2.getTop() == 0
                                    && this.mDetailInfoFirstHeader2.getParent() == this.mMyListViewV9) {
                                this.pendingDrag = true;
                                if (Logger.debug()) {
                                    Logger.v("DetailScrollView", "force pendingDrag " + y + " " + this.mY);
                                }
                            }
                            if (!this.pendingDrag) {
                                return this.isMoving;
                            }
                        }
                    }
                    if (!this.isMoving && this.pendingDrag) {
                        this.cleanVelocityTracker();
                        this.mVelocityTracker.addMovement(motionEvent);
                        this.isMoving = true;
                        this.mY = y;
                        ViewParent parent = this.getParent();
                        if (parent != null) {
                            parent.requestDisallowInterceptTouchEvent(true);
                        }
                        return this.isMoving;
                    }

                    this.pendingDrag = false;
                    if (deltaY <= this.mScaledTouchSlop) {
                        return this.isMoving;
                    }

                    this.isMoving = true;
                    this.mY = y;
                    this.ensureVelocityTracker();
                    this.mVelocityTracker.addMovement(motionEvent);
                    ViewParent parent = this.getParent();
                    if (parent != null) {
                        parent.requestDisallowInterceptTouchEvent(true);
                        break;
                    } else {
                        return this.isMoving;
                    }
                }
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_CANCEL: {
                    this.pendingDrag = false;
                    this.isMoving = false;
                    this.mPointerId = -1;
                    this.destroyVelocityTracker();
                    break;
                }
                case MotionEvent.ACTION_POINTER_DOWN: {
                    int actionIndex = motionEvent.getActionIndex();
                    this.mY = (int) motionEvent.getY(actionIndex);
                    this.mPointerId = motionEvent.getPointerId(actionIndex);
                    break;
                }
                case MotionEvent.ACTION_POINTER_UP: {
                    this.getYAndPointerId(motionEvent);
                    this.mY = (int) motionEvent.getY(motionEvent.findPointerIndex(this.mPointerId));
                    break;
                }
            }
            return isMoving;
        }
    }

    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        int childCount = this.getChildCount();
        int width = r - l;
        int height = b - t;
        for (int i = 0; i < childCount; ++i) {
            View childView = this.getChildAt(i);
            if (childView == this.mMyWebViewV9 || childView == this.mNightModeOverlay) {
                int webViewHeight = this.getWebViewHeight(height);
                childView.layout(0, 0, width, webViewHeight);
            } else if (childView == this.mBottomListViewLayout) {
                if (this.mLayoutType == 2) {
                    childView.layout(0, 0, width, height);
                } else {
                    int webViewHeight = this.getWebViewHeight(height);
                    childView.layout(0, this.getWebViewHeight(height),
                            width, this.getWebViewHeight(height) + height);
                }
            } else {
                childView.layout(0, 0, 0, 0);
            }
        }

        if (this.mShowBottomViewOnFirstLayout) {
            this.mShowBottomViewOnFirstLayout = false;
            this.post(new Runnable() {

                public final void run() {
                    if (DetailScrollView.this.getScrollY() == 0) {
                        DetailScrollView.this.handleOpenDrawer(false);
                    }
                }
            });
        }
    }

    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int widthSize = View.MeasureSpec.getSize(widthMeasureSpec);
        int widthMode = View.MeasureSpec.getMode(widthMeasureSpec);
        int heightSize = View.MeasureSpec.getSize(heightMeasureSpec);
        int heightMode = View.MeasureSpec.getMode(heightMeasureSpec);
        if (widthMode == MeasureSpec.UNSPECIFIED || heightMode == MeasureSpec.UNSPECIFIED) {
            heightSize = 0;
        } else {
            int newWidthMeasureSpec = View.MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);
            int newHeightMeasureSpec = View.MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);
            int childCount = this.getChildCount();
            for (int i = 0; i < childCount; ++i) {
                View childView = this.getChildAt(i);
                boolean measureView = childView == this.mMyWebViewV9
                        || childView == this.mBottomListViewLayout
                        || childView == this.mNightModeOverlay;

                if (measureView) {
                    childView.measure(newWidthMeasureSpec, newHeightMeasureSpec);
                }
            }
        }

        this.setMeasuredDimension(widthSize, heightSize);
    }

    public void onScrollChanged(int l, int t, int oldl, int oldt) {
        if (this.mMyOnChangedListener != null) {
            this.mMyOnChangedListener.onScrollChanged(t);
        }
    }

    @SuppressLint(value = {"ClickableViewAccessibility"})
    public boolean onTouchEvent(MotionEvent motionEvent) {
        boolean v2 = false;
        if (!this.mDisableScrollOver && !this.mDisableInfoLayer) {
            this.ensureVelocityTracker();
            this.mVelocityTracker.addMovement(motionEvent);
            switch (motionEvent.getActionMasked()) {
                case MotionEvent.ACTION_DOWN:
                    this.pendingDrag = false;
                    if (this.getChildCount() == 0) {
                        return false;
                    }

                    if (this.mScroller.isFinished()) {
                        int scrollY = this.getScrollY();
                        if (scrollY == 0 || scrollY == this.getWebViewHeight()) {
                            this.isMoving = false;
                            return false;
                        }
                    }
                    this.isMoving = !this.mScroller.isFinished();
                    if (this.isMoving) {
                        ViewParent viewParent = this.getParent();
                        if (viewParent != null) {
                            viewParent.requestDisallowInterceptTouchEvent(true);
                        }
                    }

                    if (!this.mScroller.isFinished()) {
                        this.mScroller.abortAnimation();
                    }
                    this.mY = (int) motionEvent.getY();
                    this.mPointerId = motionEvent.getPointerId(0);
                    break;
                case MotionEvent.ACTION_UP:
                    this.pendingDrag = false;
                    if (!this.isMoving) {
                        return true;
                    }
                    mVelocityTracker.computeCurrentVelocity(1000, (float) this.mScaledMaxFlingVelocity);
                    int vy = (int) mVelocityTracker.getYVelocity(this.mPointerId);
                    if (this.getChildCount() > 0) {
                        int scrollY = this.getScrollY();
                        int webViewHeight = this.getWebViewHeight();
                        boolean v0_2 = false;
                        if (scrollY == 0) {
                            scrollY = this.mMyWebViewV9.getScrollY();
                            if (vy > 0) {
                                if (scrollY + webViewHeight < this.mMyWebViewV9.getComputedVerticalScrollRange()) {
                                    this.mMyWebViewV9.flingScroll(0, -vy);
                                    v2 = true;
                                }
                                v0_2 = v2;
                            } else {
                                if (scrollY <= 0) {
                                    v0_2 = false;
                                } else {
                                    this.mMyWebViewV9.flingScroll(0, -vy);
                                    v0_2 = true;
                                }
                            }
                        } else {
                            v0_2 = false;
                        }

                        if (!v0_2 && this.F != 0) {
                            Logger.w("DetailScrollView", "mMyListViewV9.tryFling()  -vy=" + -vy);
                            this.mMyListViewV9.tryFling(-vy);
                            v0_2 = true;
                        }

                        if (!v0_2) {
                            this.startFling(-vy);
                        }
                    }
                    this.mPointerId = -1;
                    this.g();
                    break;
                case MotionEvent.ACTION_MOVE: {
                    int pointerIndex = motionEvent.findPointerIndex(this.mPointerId);
                    if (pointerIndex == -1) {
                        Logger.w("DetailScrollView", "Invalid pointerId=" + this.mPointerId
                                + " in onTouchEvent");
                    } else {
                        int currentY = (int) motionEvent.getY(pointerIndex);
                        int deltaY = this.mY - currentY;
                        if (!this.isMoving && Math.abs(deltaY) > this.mScaledTouchSlop) {
                            ViewParent viewParent = this.getParent();
                            if (viewParent != null) {
                                viewParent.requestDisallowInterceptTouchEvent(true);
                            }
                            this.isMoving = true;
                            if (deltaY > 0) {
                                deltaY -= this.mScaledTouchSlop;
                            } else {
                                deltaY += this.mScaledTouchSlop;
                            }
                        }
                        if (!this.isMoving) {
                            return true;
                        }

                        this.pendingDrag = false;
                        this.mY = currentY;
                        int scrollY = this.getScrollY();
                        int scrollRange = this.getScrollRange();
                        int newY = scrollY + deltaY;
                        if (deltaY > 0 && newY >= scrollRange
                                || deltaY < 0 && newY <= 0) {
                            this.mVelocityTracker.clear();
                        }
                        int webViewHeight = this.getWebViewHeight();
                        int webViewScrollY = this.mMyWebViewV9.getScrollY();
                        if (deltaY < 0) {
                            if (this.F < 0) {
                                if (deltaY >= this.F) {
                                    this.F -= deltaY;
                                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                        this.mMyListViewV9.setSelectionFromTop(0, this.F);
                                    } else {
                                        this.mMyListViewV9.setSelection(0);
                                    }
                                    return true;
                                } else {
                                    deltaY -= this.F;
                                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                        this.mMyListViewV9.setSelectionFromTop(0, 0);
                                    } else {
                                        this.mMyListViewV9.setSelection(0);
                                    }
                                    this.F = 0;
                                }
                            }

                            scrollRange = deltaY;
                            if (newY < 0) {
                                scrollRange = -scrollY;
                            }

                            if (scrollRange != 0) {
                                this.scrollBy(0, scrollRange);
                            }

                            if (scrollRange != 0) {
                                return true;
                            }

                            if (deltaY >= 0) {
                                return true;
                            }

                            if (scrollY != 0) {
                                return true;
                            }

                            if (webViewScrollY <= 0) {
                                return true;
                            }

                            if (deltaY < -webViewScrollY) {
                                deltaY = -webViewScrollY;
                            }

                            this.mMyWebViewV9.scrollBy(0, deltaY);
                            return true;
                        }

                        if (deltaY <= 0) {
                            return true;
                        }

                        if (scrollY != 0 || this.mMyWebViewV9 == null) {
                            scrollRange = 0;
                        } else {
                            scrollRange = this.mMyWebViewV9.getComputedVerticalScrollRange();
                            if (webViewScrollY + webViewHeight < scrollRange) {
                                scrollRange = deltaY + webViewScrollY + webViewHeight > scrollRange ? scrollRange - webViewScrollY - webViewHeight : deltaY;
                                this.mMyWebViewV9.scrollBy(0, scrollRange);
                                scrollRange = 1;
                            } else {
                                scrollRange = 0;
                            }
                        }

                        if (scrollRange != 0) {
                            return true;
                        }

                        if (newY > webViewHeight) {
                            deltaY = webViewHeight - scrollY;
                            this.F -= newY - webViewHeight;
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                this.mMyListViewV9.setSelectionFromTop(0, this.F);
                            } else {
                                this.mMyListViewV9.setSelection(0);
                            }
                        }

                        if (deltaY != 0) {
                            this.scrollBy(0, deltaY);
                        }
                        if (deltaY + scrollY != this.getWebViewHeight()) {
                            return true;
                        }
                        this.c = false;
                    }

                    break;
                }
                case MotionEvent.ACTION_CANCEL:
                    this.pendingDrag = false;
                    if (this.isMoving) {
                        this.mPointerId = -1;
                        this.g();
                        break;
                    } else {
                        return true;
                    }
                case MotionEvent.ACTION_POINTER_DOWN:
                    int actionIndex = motionEvent.getActionIndex();
                    this.mY = (int) motionEvent.getY(actionIndex);
                    this.mPointerId = motionEvent.getPointerId(actionIndex);
                    break;
                case MotionEvent.ACTION_POINTER_UP:
                    this.getYAndPointerId(motionEvent);
                    this.mY = (int) motionEvent.getY(motionEvent.findPointerIndex(this.mPointerId));
                    break;
            }
            v2 = true;
        }

        return v2;
    }

    public void requestDisallowInterceptTouchEvent(boolean arg1) {
    }

    public void setDisableInfoLayer(boolean disableInfoLayer) {
        this.mDisableInfoLayer = disableInfoLayer;
        if (this.mDisableInfoLayer) {
            this.setVerticalScrollBarEnabled(false);
        }
    }

    public void setDisableScrollOver(boolean disableScrollOver) {
        this.mDisableScrollOver = disableScrollOver;
        if (this.mDisableScrollOver) {
            this.setVerticalScrollBarEnabled(false);
        }
    }

    public void setDisallowIntercept(boolean disallowIntercept) {
        this.mDisallowIntercept = disallowIntercept;
        if (disallowIntercept) {
            this.setVerticalScrollBarEnabled(false);
        }
    }

    public void setEnableDetectContentSizeChange(boolean enableDetectContentSizeChange) {
        this.mEnableDetectContentSizeChange = enableDetectContentSizeChange;
        if (!enableDetectContentSizeChange && this.mMyWebViewV9 != null) {
            this.mMyWebViewV9.setDetectContentSize(false);
        }
    }

    public void setLayoutType(int arg2) {
        this.mLayoutType = arg2;
        if (arg2 != 1) {
            this.setVerticalScrollBarEnabled(false);
        }
    }

    public void setMyOnChangedListener(MyOnChangedListener arg1) {
        this.mMyOnChangedListener = arg1;
    }

    public void setShowBottomViewOnFirstLayout(boolean showBottomViewOnFirstLayout) {
        this.mShowBottomViewOnFirstLayout = showBottomViewOnFirstLayout;
    }

    public void setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled) {
        int v2 = 1;
        if (this.mIsVerticalScrollBarEnabled) {
            super.setVerticalScrollBarEnabled(false);
            boolean isVerticalScrollBarEnabled = this.isVerticalScrollBarEnabled();
            boolean willNotDraw = !isVerticalScrollBarEnabled;
            this.setWillNotDraw(willNotDraw);
            OnScrollBarShowListener onScrollBarShowListener = isVerticalScrollBarEnabled ? new OnScrollBarShowListener(this) : null;
            if (this.mMyWebViewV9 != null) {
                mMyWebViewV9.setVerticalScrollBarEnabled(!isVerticalScrollBarEnabled);
                this.mMyWebViewV9.setOnScrollBarShowListener(onScrollBarShowListener);
            }
            mMyListViewV9.setVerticalScrollBarEnabled(!isVerticalScrollBarEnabled);
            this.mMyListViewV9.setOnScrollBarShowListener(onScrollBarShowListener);
            this.mIsVerticalScrollBarEnabled = isVerticalScrollBarEnabled;
            if (!isVerticalScrollBarEnabled) {
                return;
            }

            if (this.mMyListViewV9 == null) {
                return;
            }

            if (this.mMyListViewV9.isSmoothScrollbarEnabled()) {
                v2 = 100;
            }

            this.G = Math.max(1f, UIUtils.dp2px(this.getContext(), 100f) / (((float) v2)));
        }
    }

    public interface MyOnChangedListener {
        void setInfoTitleBarVisibility(boolean arg1);

        void onScrollChanged(int l);

        void a();
    }
}

